package com.reflect;

import com.domain.Person;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;

//获取构造方法
public class ReflectDemo3 {

    public static void main(String[] args) throws Exception {
        //获取class对象
        Class<Person> personClass = Person.class;
        //Constructor 构造方法
        Constructor<Person> constructor = personClass.getConstructor(String.class, int.class);
        System.out.println(constructor);
        //创建对象
        Person person = constructor.newInstance("张三", 23);
        System.out.println(person);

        System.out.println("==================");
        //Constructor 构造方法
        Constructor<Person> constructor1 = personClass.getConstructor();
        System.out.println(constructor1);
        //创建对象
        Person person1 = constructor1.newInstance();
        System.out.println(person1);
        //空参
        Person person2 = personClass.newInstance();
        System.out.println(person2);

        constructor1.setAccessible(true);

    }

}
